(** Common code for loading modules *)

open Lexing;;

let load_from_channel ch modname = 
    let lexbuf = Lexing.from_channel ch in
    lexbuf.lex_start_p <- { pos_fname = modname; pos_lnum = 1; pos_bol = 0; pos_cnum = 0; };
    let st = ref (Stack.create ()) in
    Stack.push 0 !st;
    Parser.apy_module (Lexer.token st (ref 0)) lexbuf
;;

let load_builtins include_path = 
    load_from_channel (open_in (include_path ^ "__builtins__.apy")) "__builtins__";;
